<%@page import="com.sun.xml.internal.bind.CycleRecoverable.Context"%>
<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
    
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="utils.DBConnector"%>
<%@page import="utils.Printer"%>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type="text/javascript" src="applyXSL.js"></script>
<script type="text/javascript">

	function display(){
		var e = document.getElementById("selection");
		var strUser = e.options[e.selectedIndex].text;
		displayResult(strUser);
	}
	
	function deleteSS(){
		var e = document.getElementById("selection");
		var strUser = e.options[e.selectedIndex].text;
		window.location="DeleteStyleSheet?selection=" + strUser;
		request.send(null);
		alert("ss2");
	}
</script>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1255" />
<title>Custom Your XSLT</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body onload = "setPage('custom_stylesheet')">
<%@ include file="/WEB-INF/private/body_wrapper_header.html" %>

<%

if (request.getSession(false) == null || request.getSession(false).getAttribute("username") == null){
	response.sendError(HttpServletResponse.SC_FORBIDDEN, "Please login first");
	return;
}

String username = request.getSession(false).getAttribute("username").toString();

DBConnector dbConn = new DBConnector();

PreparedStatement stmnt = dbConn.getConnection().prepareStatement(
			"SELECT style_name, xslt " 						+  
			"FROM user_stylesheets  " 			+  
			"WHERE username = ? ;"  );
 
stmnt.setString(1, username);
ResultSet res = stmnt.executeQuery();

%>
<p>
<a href="UserSchedule">Get Schedule as XML</a> <br/>
<a href="schedSchema.dtd">Get Schedule DTD</a> <br/>
</p>
<form method="post" enctype='multipart/form-data' action="AddNewStyleSheet">
<table border="3px">
	
		<tr>
			<td>
				<input type="file" name="upFile" id="upFile"/>
			</td>
			<td>
				<input type="submit" value="Upload" name="submitType"/>
			</td>
			<td> </td>
		</tr>
		<tr>
			<td>
				Select Your Stylesheet:
				<select id="selection" name="selection">
					<option value="Default" > Default </option>
					<option value="Custom" > Custom </option>
					<% 
					while(res.next()){
						out.println("<option value=\"" + res.getString(1) + "\">" + res.getString(1) +"</option>");
					}
					%>
				</select>
			</td>
			<td>
				<input type="button" value="Get Schedule" onclick="display()"></input>
			</td>
			<td>
				<input type="button" onclick="deleteSS()" value="Delete Stylesheet" name="submitType"/>
			</td>			
		</tr>		
	
</table>
</form>
<p><br/></p>
<div id="sched"></div>


<% dbConn.close(); %>
<%@ include file="/WEB-INF/private/body_wrapper_footer.html" %>
</body>
</html>